<?php
declare(strict_types=1);

namespace SixShop\WechatPay\Controller;

use SixShop\Core\Request;
use SixShop\WechatPay\Entity\WechatpayTransferBillEntity;
use SixShop\WechatPay\Enum\TransferBillStatusEnum;
use think\Response;
use function SixShop\Core\page_response;
use function SixShop\Core\success_response;

class TransferBillController
{
    public function index(Request $request, WechatpayTransferBillEntity $transferBillEntity): Response
    {
        $params = $request->get([
            'state/s' => 'all',
            'out_bill_no/s' => '',
        ]);
        $page = $request->pageAndLimit();
        $stats = $transferBillEntity->getTransferBillStats($params);
        return page_response(
            data: $stats,
            page: $transferBillEntity->getTransferBillList($params, $page)
        );
    }

    public function refresh(int $id, WechatpayTransferBillEntity $transferBillEntity): Response
    {
        return success_response($transferBillEntity->refreshTransferBill($id));
    }

    public function approve(int $id, WechatpayTransferBillEntity $transferBillEntity): Response
    {
        return success_response($transferBillEntity->approveTransferBill($id));
    }

    public function reject(int $id, Request $request, WechatpayTransferBillEntity $transferBillEntity): Response
    {
        return success_response($transferBillEntity->rejectTransferBill($id, $request->post('fail_reason/s')));
    }
}